package gui.inventory;

import gui.product.ProductData;
import hit.core.Product;
import hit.core.ProductContainer;

import java.util.Observable;
import java.util.Observer;

public class ProductObserver implements Observer {
	private IInventoryView view;
	private InventoryController controller;
	
	/**
	 * @param view the view this observer is associated with
	 * */
	public ProductObserver(IInventoryView view, InventoryController controller) {
		this.view = view;
		this.controller = controller;
	}
	
	@Override
	public void update(Observable o, Object response) {
		
		ProductContainerData data_selectedContainer = view.getSelectedProductContainer();
		ProductContainer container = (ProductContainer)data_selectedContainer.getTag();
		
		ProductData data_selectedProduct = view.getSelectedProduct();
		
		if (data_selectedProduct != null) {
			Product product = (Product)data_selectedProduct.getTag();
			
			controller.DrawItems(container, product);
		}
		
		controller.DrawProducts(container, true);
		
	}
	
}
